package com.skzh.healthy.service.impl;

import com.skzh.healthy.domain.DroneBattery;
import com.skzh.healthy.domain.vo.BatteryStatsVO;
import com.skzh.healthy.mapper.DroneBatteryMapper;
import com.skzh.healthy.service.IDroneBatteryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;



@Service
public class DroneBatteryServiceImpl implements IDroneBatteryService {

    @Autowired
    private DroneBatteryMapper batteryMapper;

    @Override
    public List<DroneBattery> selectBatteryList(DroneBattery battery) {
        return batteryMapper.selectBatteryList(battery);
    }

    @Override
    public List<DroneBattery> selectOnlineBatteries(DroneBattery battery) {
        battery.setIsOnline("1");
        return batteryMapper.selectBatteryList(battery);
    }

    @Override
    public List<DroneBattery> selectAlarmBatteries() {
        DroneBattery battery = new DroneBattery();
        battery.setStatus("1");
        return batteryMapper.selectBatteryList(battery);
    }

    @Override
    public BatteryStatsVO getBatteryStats() {
        BatteryStatsVO statsVO = new BatteryStatsVO();
        BatteryStatsVO.StatusCount statusCount = new BatteryStatsVO.StatusCount();

        try {
            // 获取基本统计数据
            BatteryStatsVO basicStats = batteryMapper.selectBatteryStats();
            if (basicStats != null) {
                statsVO.setNormalCount(basicStats.getNormalCount());
                statsVO.setWarningCount(basicStats.getWarningCount());
                statsVO.setScrappedCount(basicStats.getScrappedCount());

                // 设置状态数量
                statusCount.setNormal(basicStats.getNormalCount());
                statusCount.setWarning(basicStats.getWarningCount());
                statusCount.setScrapped(basicStats.getScrappedCount());
                statsVO.setStatusCount(statusCount);
            }

            // 获取状态统计数据
            List<BatteryStatsVO.StatusStats> statusStats = batteryMapper.selectBatteryStatusStats();
            if (statusStats != null) {
                statsVO.setStatusStats(statusStats);
            }

        } catch (Exception e) {

        }

        return statsVO;
    }


    @Override
    public int scrapBattery(Long id) {
        DroneBattery battery = new DroneBattery();
        battery.setId(id);
        battery.setStatus("2"); // 设置为报废状态
        return batteryMapper.updateDroneBattery(battery);
    }
}
